// pages/merchantInfo/merchantInfo.js
var app = getApp();
Page({

  data: {
    mid:'',
    imgUrl: app.globalData.domin,
    merchantInfo: [],
    merchantGoods: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //发起请求，获取列表列表
    wx.showLoading({
      title: '加载中',
      mask: true
    });

    this.setData({
      mid: options.mid
    })
    this.getMerchantInfo();
  },
  
  // 请求店家详情接口
  getMerchantInfo () {
    let that = this;
    var data = {
      map: 'applet_merchant_home',
      m_id: that.data.mid
    }
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        if (res.data.ec == 400) {
          wx.showToast({
            title: res.data.em,
            icon: 'none',
            duration: 2000
          });
          return;
        }
        that.setData({
          merchantInfo: res.data.data.merchant_info,
          merchantGoods: res.data.data.goods_list
        })
      },
      complete: function () {
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  cllaPhone: function (e) { // 拨打电话
    let phone = this.data.merchantInfo.cm_phone;
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  //打开地图
  goNavigation: function (e) {
    let [longitude,latitude] = JSON.parse(this.data.merchantInfo.cm_address_point);
    wx.openLocation({
      latitude:Number(latitude),
      longitude:Number(longitude),
      scale:18,
    })
  },


  goAllStore: function(){ // 门店列表
    wx.navigateTo({
      url: '/subpages1/allStore/allStore?mid=' + this.data.mid,
    })
  },

  goGoodsList: function (e) { // 跳转到商品列表
    wx.navigateTo({
      url: '/subpages1/searchList/searchList?mid=' + this.data.mid,
    })
  },

  goGoodsDtail: function (e) { // 跳转到商品详情
    let goodsId = e.currentTarget.dataset.gid
    wx.navigateTo({
      url: '/subpages1/goodDetail/goodDetail?id=' + goodsId
      })
  },

})